package com.wanjia.seal.manager.controller;


import com.wanjia.seal.manager.annotation.LoginToken;
import com.wanjia.seal.manager.entity.SysMenu;
import com.wanjia.seal.manager.entity.SysRoleMenu;
import com.wanjia.seal.manager.mapper.SysRoleMenuMapper;
import com.wanjia.seal.manager.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Controller
@RequestMapping("/api")
@Api(tags = "角色菜单")
@Slf4j
public class SysRoleMenuController extends BaseController{

    @Autowired
    SysRoleMenuMapper sysRoleMenuMapper;


    @ResponseBody
    @GetMapping("/allrolemenu")
    @ApiOperation(value = "查询所有角色菜单关系表", notes = "查询是否成功")
    @LoginToken
    public JsonResult<List<SysRoleMenu>> getAll() {
        List<SysRoleMenu> sysRoleMenus = sysRoleMenuMapper.selectList(null);
        return new JsonResult<>(OK,sysRoleMenus);
    }

    @ResponseBody
    @GetMapping("/rolemenu")
    @ApiOperation(value = "用ID查询角色菜单关系表", notes = "查询是否成功")
    @LoginToken
    public JsonResult<SysRoleMenu> getById(Integer RoleId){
        SysRoleMenu sysRoleMenu = sysRoleMenuMapper.selectById(RoleId);
        return new JsonResult<>(OK,sysRoleMenu);
    }
    @ResponseBody
    @PutMapping("/updaterolemenu")
    @ApiOperation(value = "更新角色菜单关系表", notes = "更新角色菜单关系表是否成功")
    @LoginToken
    public JsonResult upData(@RequestBody  SysRoleMenu sysRoleMenu){
        sysRoleMenuMapper.updateById(sysRoleMenu);
        return new JsonResult(OK);
    }

    @ResponseBody
    @PostMapping("/addrolemenu")
    @ApiOperation(value = "添加角色菜单关系表", notes = "添加角色菜单关系表是否成功")
    @LoginToken
    public JsonResult addRole(@RequestBody SysRoleMenu sysRoleMenu){
        sysRoleMenuMapper.insert(sysRoleMenu);
        return new JsonResult(OK);
    }
    @ResponseBody
    @DeleteMapping("/deleterolemenu")
    @ApiOperation(value = "删除角色菜单关系表", notes = "删除角色菜单关系表是否成功")
    @LoginToken
    public JsonResult update(Integer RoleId) {
        sysRoleMenuMapper.deleteById(RoleId);
        return new JsonResult(OK);
    }

}
